package org.app.Controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.app.Entity.*;
import org.app.Entity.comm.Result;
import org.app.Service.IPersonalExercisePlanService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin("*")
@RequestMapping("/personal-plan")
@Slf4j
public class PersonalExercisePlanController {
    @Resource
    private IPersonalExercisePlanService planService;
    @GetMapping("/listByCID")
    Result<List<ExercisePlan>> listExercisePlanByCID(@RequestParam("c_id") String c_id){
        return planService.listExercisePlanByCIDInTwoDays(c_id);
    }
    @GetMapping("/getByPID")
    Result<ExercisePlan> getExercisePlanByPID(@RequestParam("p_id") String p_id){
        return planService.listExercisePlanByPID(p_id);
    }
    // 提交新的训练计划，不需要提供 save_id 参数
    @PostMapping("/createPlan")
    Result<Integer> createExercisePlan(@RequestBody List<ExercisePlan> exercisePlanList) {
        return planService.createExercisePlan(exercisePlanList, "1");
    }
    @PostMapping("/updatePlan")
    Result<Integer> updateExercisePlan(@RequestBody ExercisePlan exercisePlan){
        return planService.updateExercisePlan(exercisePlan);
    }
    @DeleteMapping("/deletePlan")
    Result<Integer> deleteExercisePlan(@RequestParam("p_id") String p_id){
        return planService.deleteExercisePlan(p_id);
    }
    @PutMapping("/finish")
    Result<Integer> finishExercisePlan(@RequestParam("p_id") String p_id,
                                       @RequestParam("c_id") String c_id){
        return planService.finishExercisePlan(p_id,c_id);
    }

    @GetMapping("/listSave")
    Result<Save> listSave(@RequestParam("c_id") String c_id){
        return planService.listSave(c_id);
    }

    // 保存功能
    @PostMapping("/save")
    Result<String> savePlans(@RequestBody Save save){
        return planService.savePlans(save);
    }
//    @PostMapping("/saveSD")
//    Result<Integer> saveSD(@RequestBody List<SaveSD> sdList, @RequestParam("save_id") String save_id){
//        return planService.saveStrengthData(sdList,save_id);
//    }
//    @PostMapping("/saveTable")
//    Result<Integer> saveNewTable(@RequestBody List<SaveTable> tableList, @RequestParam("save_id") String save_id){
//        return planService.saveNewTable(tableList,save_id);
//    }

    // 修改保存功能
    @PutMapping("/updateSave")
    Result<Integer> updateSave(@RequestBody Save save){
        return planService.updateSave(save);
    }
//    @PutMapping("updateSD")
//    Result<Integer> updateSD(@RequestBody List<SaveSD> sdList){
//        return planService.updateStrengthData(sdList);
//    }
//    @PutMapping("updateTable")
//    Result<Integer> updateTable(@RequestBody List<SaveTable> tableList ){
//        return planService.updateNewTable(tableList);
//    }
}
